package com.wanxi.user;

import java.util.Locale;
import java.util.Scanner;

/**
 * 登录模拟
 * 1.设置用户名和密码
 * 2.应该另写一个登录方法
 * 3.首先设置次数
 * 4.设置一个循环，判断是否还可以继续登录
 * 5.判断是否登录成功 equals
 */
public class Login {
    public static void main(String[] args) {
        String username = "admin";
        String password = "123456";
        boolean success = login(username, password);
        System.out.println("用户登录" + (success ? "成功" : "失败"));
    }

    private static boolean login(String username, String password) {

        Scanner scanner = new Scanner(System.in);
        int count = 3;
        while (true) {
            System.out.println("请输入用户名:");
            String user = scanner.next().toLowerCase(Locale.ROOT).trim();
            System.out.println("请输入密码：");
            String pass = scanner.next();
            if (username.equals(user) && password.equals(pass)) {
                return true;
            } else {
                count--;
                System.out.println("请重新输入用户名和密码：你还有 " + count + " 次机会");
                if (count <= 0) {
                    System.out.println("你机会用完了");
                    return false;
                }
            }
        }
    }

}
